// pages/method/method.js

Page({
    /**
     * 页面的初始数据
     */
    data: {
        text: ['染料调配', '设计图案并扎花', '棉布寖水', '染色', '氧化', '洗涤', '晾晒', '熨烫'],
        method: ['云扎法', '圆形扎法', '夹扎法', '捆扎法'],
        previewPath: '',
        displaytext: '',
        circledisplay: 'none',
        gradientColor: {
            '0%': '#ffd01e',
            '100%': '#ee0a24',
        },
        circlevalues: [12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100],
        circlevalue: 0
    },
    delayedLoop: function (i, max, delay, callback) {
        if (i >= max) {
            return;
        }
        callback(i);
        setTimeout(() => {
            this.delayedLoop(i + 1, max, delay, callback);
        }, delay);
    },
    preview(e) {
        this.setData({
            previewPath:''
        },()=>{
            const index = e.currentTarget.dataset.index;
            this.setData({
            circledisplay: 'block'
        }, () => {
            this.delayedLoop(0, 9, 1000, (i) => {
                if (i == 8) {
                    this.setData({
                        circlevalue: this.data.circlevalues[i],
                        displaytext: this.data.text[i]
                    }, () => {
                        const path = 'cloud://caomuran-1g8779m369008bfe.6361-caomuran-1g8779m369008bfe-1325524721/preview/result/' + this.data.method[index] + '.png';
                        console.log(path);
                        this.setData({
                            circledisplay: 'none',
                            previewPath: path
                        },()=>{
                            this.setData({
                                circlevalue:0
                            })
                        })
                    })
                }
                this.setData({
                    circlevalue: this.data.circlevalues[i],
                    displaytext: this.data.text[i]
                })
            });
        })
        })
    }
})

// console.log('执行回调');
//             for (let i = 0; i < 8; i++) {

//             }